#include <Ogre.h>
#include "marble.h"
using namespace Ogre;

Marble::Marble()
{
}
Marble::Marble(SceneManager *mgr, Vector3 pos)
{
	mSceneMgr = mgr;
	mMarble = mSceneMgr->createEntity("Marble",SceneManager::PT_SPHERE);
	mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("MarbleNode",pos);
	mNode->attachObject(mMarble);
	mNode->setScale(.1,.1,.1);
	mVelocity = Vector3::ZERO;
	mAcceleration = Vector3::ZERO;
	mMass = 10;
	Root::getSingletonPtr()->addFrameListener(this);
}
Marble::~Marble()
{
}

void Marble::start()
{
}

bool Marble::frameStarted(const Ogre::FrameEvent &evt)
{
	Ogre::Real Pos2,Vel2,Vel3,Time1,Time2;
	Ogre::Vector3 Pos1,Vel1;
	if(evt.timeSinceLastFrame != 0 && evt.timeSinceLastFrame < .1)
	{
		mAcceleration = Vector3(0,2.5*evt.timeSinceLastFrame,0);
		mVelocity -= mAcceleration;
		mNode->translate(mVelocity);
		if(mNode->getPosition().y <= 6)
		{
			mNode->translate(-mVelocity);
			mVelocity.y *= -.9;
		}
	}
	return true;
}
bool Marble::frameEnded(const Ogre::FrameEvent &evt)
{
	return true;
}

bool Marble::collision(Ogre::Vector3 point1, Ogre::Vector3 point2, Ogre::Vector3 point3)
{
	return false;
}